import Taro from "@tarojs/taro";
import React from "react";
import { View, Text } from "@tarojs/components";
import { wxLogin } from "./api";
import css from "./index.module.less";

export default function Index() {
  const login = () => {
    console.log("ooooo");
    Taro.login({
      success: function (res) {
        console.log(res.code);
        wxLogin(`/login/wxLogin/${res.code}`).then((r) => {
          if (r.code === 200) {
            // 微信团队抛弃了wx.getUserInfo、wx.getUserProfile接口
            // 获取用户头像将统一返回默认灰色头像，昵称将统一返回 “微信用户”
            // Taro.getUserInfo({
            //   success: function (res) {
            //     console.log(res.userInfo);
            //   }
            // })
            Taro.setStorage({
              key:"userInfo",
              data:r.data
            })
            Taro.navigateTo({url: 'index'});
            console.log(r.data);
          }
          
        });
      },
    });
  };

  return (
    <React.Fragment>
      <View className={css.content}>
        <button onClick={login}>
          Click me
        </button>
      </View>
    </React.Fragment>
  );
}